package com.xiaozhichao.javaapi.designpattern.observer.model.userdefined;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * 被观察者
 */
public class WechatServer implements Observerable {

    private List<Observer> list;

    public WechatServer() {
        list = new ArrayList<Observer>();
    }

    @Override
    public void registerObserver(Observer o) {
        list.add(o);
    }

    @Override
    public void removeObserver(Observer o) {
        list.remove(o);
    }

    @Override
    public void notifyObserver(Object obj) {
        Iterator<Observer> it = list.iterator();
        while(it.hasNext()){
            it.next().update(obj);
        }
    }

}
